package com.jfinal.club._admin.wordantonyms;

import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.club.my.wordantonyms.MyWordantonymsValidator;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.club.common.controller.BaseController;
import com.jfinal.kit.Ret;
import com.jfinal.club.common.model.Word;
import com.jfinal.club.common.model.Wordantonyms;
import com.jfinal.club.common.model.Wordmeaning;
import com.jfinal.club.index.IndexService;

/**
 * 反义词管理控制器
 */
public class WordantonymsAdminController extends BaseController {

	@Inject
	WordantonymsAdminService srv;

	public void index() {
		Page<Wordantonyms> wordantonymsPage = srv.paginate(getParaToInt("p", 1));
		setAttr("wordantonymsPage", wordantonymsPage);
		render("index.html");
	}

	/**
	 * 创建
	 */
	public void add() {
		render("add_edit.html");
	}

	/**
	 * 提交创建
	 */
	@Before(MyWordantonymsValidator.class)
	public void save() {
		Wordantonyms wordantonyms = getBean(Wordantonyms.class);
		Ret ret = srv.save(getLoginAccountId(),wordantonyms);
		renderJson(ret);
	}

	/**
	 * 修改
	 */
	public void edit() {
		keepPara("p");	// 保持住分页的页号，便于在 ajax 提交后跳转到当前数据所在的页
		setAttr("wordantonyms", srv.edit(getParaToInt("id")));
		render("add_edit.html");
	}

	/**
	 * 提交修改
	 */
	@Before(MyWordantonymsValidator.class)
	public void update() {
		Wordantonyms wordantonyms = getBean(Wordantonyms.class);
		Ret ret = srv.update(wordantonyms);
		renderJson(ret);
	}
	/**
	 * 删除 wordantonyms
	 */
	public void delete() {
		Ret ret = srv.delete(getParaToInt("id"));
		renderJson(ret);
	}
}


